<?php

use App\Http\Controllers\App\Attachment\AttachmentController;
use App\Http\Controllers\App\Content\ArticleCategoryController;
use App\Http\Controllers\App\Content\ArticleController;
use App\Http\Controllers\App\Forum\ForumCategoryController;
use App\Http\Controllers\App\Forum\ForumController;
use App\Http\Controllers\User\PermissionController;
use App\Http\Controllers\User\RoleController;
use App\Http\Controllers\User\UserController;
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');

require __DIR__.'/auth.php';

/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
|
| 后台需要授权的路由 admin
|
*/

//后台控制台
Route::get('/home', [HomeController::class, 'index'])->name('home');
Route::get('/home/console', [HomeController::class, 'console'])->name('home.console');
//Route::get('/clear','IndexController@clear')->name('admin.clear');

// 获取市或县
//Route::get('district/city','DistrictController@city')->name('admin.district.city');

//用户
Route::name('user.')->middleware(['auth'])->group(function () {
    //网站用户
    Route::resource('user', UserController::class);

    //角色管理
    Route::resource('role', RoleController::class);
    //分配权限
    Route::get('role/{id}/permission', [RoleController::class, 'permission'])->name('user.role.permission');
    Route::put('role/{id}/assignPermission', [RoleController::class, 'assignPermission'])->name('user.role.assignPermission');

    //权限管理
    Route::resource('permission', PermissionController::class);
});

//应用
Route::name('app.')->middleware(['auth'])->group(function () {

    //内容系统
    Route::name('content.')->group(function () {
        Route::resource('article', ArticleController::class);
        Route::resource('article_category', ArticleCategoryController::class);
    });

    //社区系统
    Route::name('forum.')->group(function () {
        Route::resource('forum', ForumController::class);
        Route::resource('forum_category', ForumCategoryController::class);
    });

    //文件系统
    Route::resource('attachment', AttachmentController::class);
});

//设置
Route::name('set.')->middleware(['auth'])->group(function () {

    //系统设置
    Route::name('system.')->group(function () {
        Route::get('website', [RoleController::class, 'permission'])->name('user.role.permission');
        Route::put('website', [RoleController::class, 'assignPermission'])->name('user.role.assignPermission');
    });

});
